/*
 * $Id$
 *
 * Copyright ( c ) 2014 XuNuo Corporation. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of XuNuo
 * Corporation ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with XuNuo Corporation or a XuNuo
 * authorized reseller (the "License Agreement"). XuNuo may make changes to the
 * Confidential Information from time to time. Such Confidential Information may
 * contain errors.
 *
 * EXCEPT AS EXPLICITLY SET FORTH IN THE LICENSE AGREEMENT, XuNuo DISCLAIMS ALL
 * WARRANTIES, COVENANTS, REPRESENTATIONS, INDEMNITIES, AND GUARANTEES WITH
 * RESPECT TO SOFTWARE AND DOCUMENTATION, WHETHER EXPRESS OR IMPLIED, WRITTEN OR
 * ORAL, STATUTORY OR OTHERWISE INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A
 * PARTICULAR PURPOSE. XuNuo DOES NOT WARRANT THAT END USER'S USE OF THE
 * SOFTWARE WILL BE UNINTERRUPTED, ERROR FREE OR SECURE.
 *
 * XuNuo SHALL NOT BE LIABLE TO END USER, OR ANY OTHER PERSON, CORPORATION OR
 * ENTITY FOR INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL
 * DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, WHETHER IN AN
 * ACTION IN CONTRACT, TORT OR OTHERWISE, EVEN IF XuNuo HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES. XuNuo' TOTAL LIABILITY TO END USER SHALL NOT
 * EXCEED THE AMOUNTS PAID FOR THE XuNuo SOFTWARE BY END USER DURING THE PRIOR
 * TWELVE (12) MONTHS FROM THE DATE IN WHICH THE CLAIM AROSE.  BECAUSE SOME
 * STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO END USER.
 *
 * Copyright version 2.0
 */
package com.th.supcom.pds.phamapply.client.widget.checkdispense;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.th.supcom.pds.phamapply.client.widget.phamdispense.PhamDispenseFields;

/**
 * 住院核对发药操作员记录界面
 * 
 * @author 杨冲
 */
public class InpCheckDispenseOperateRecordWindow extends Window
{
    private InpCheckDispenseButtons m_inpCheckDispenseButtons;
    private InpCheckDispenseAction m_inpCheckDispenseAction;
    private TextField <String> m_empIDField;
    private Button m_confirmButton;
    private Button m_cancelButton;
    private PhamDispenseFields m_phamDispenseFields;

    public InpCheckDispenseOperateRecordWindow ()
    {

    }

    /**
     * 设置住院摆药按钮组件
     * 
     * @param inpCheckDispenseButtons
     */
    public void setInpCheckDispenseButtons (InpCheckDispenseButtons inpCheckDispenseButtons)
    {

        this.m_inpCheckDispenseButtons = inpCheckDispenseButtons;
    }

    /**
     * 设置摆药Action
     * 
     * @param dispenseAction
     */
    public void setDispenseAction (InpCheckDispenseAction dispenseAction)
    {

        m_inpCheckDispenseAction = dispenseAction;
    }

    /**
     * 设置核对发药组件
     * 
     * @param phamDispenseFields
     */
    public void setPhamDispenseFields (PhamDispenseFields phamDispenseFields)
    {

        m_phamDispenseFields = phamDispenseFields;
    }

    /**
     * 初始化UI
     */
    public void initUI ()
    {
        setHeading ("操作记录");
        setPixelSize (250, 150);
        setModal (true);

        FormPanel formPanel = new FormPanel ();
        formPanel.setButtonAlign (HorizontalAlignment.CENTER);
        formPanel.setHeaderVisible (false);
        formPanel.setBodyBorder (false);
        formPanel.setBorders (false);
        FormLayout layout = new FormLayout ();
        layout.setDefaultWidth (150);
        layout.setLabelWidth (60);

        formPanel.setLayout (layout);

        TextField <String> m_empNameField;
        m_empIDField = m_phamDispenseFields.getEmpID ();
        m_empNameField = m_phamDispenseFields.getEmpName ();
        formPanel.add (m_empIDField);
        formPanel.add (m_empNameField);
        m_confirmButton = m_inpCheckDispenseButtons.getConfirmButton ();
        m_cancelButton = m_inpCheckDispenseButtons.getCancelButton ();
        formPanel.addButton (m_confirmButton);
        formPanel.addButton (m_cancelButton);
        add (formPanel);

        // 初始化事件和清空数据
        addConfirmDispenseListener ();
        addCancelListener ();
    }

    /**
     * 点击确认按钮进行摆药
     */
    private void addConfirmDispenseListener ()
    {
        m_confirmButton.addSelectionListener (new SelectionListener <ButtonEvent> ()
        {

            @Override
            public void componentSelected (ButtonEvent ce)
            {
                m_inpCheckDispenseAction.checkDispense (m_empIDField.getValue ());
                hide ();
            }
        });
    }

    private void addCancelListener ()
    {
        m_cancelButton.addSelectionListener (new SelectionListener <ButtonEvent> ()
        {

            @Override
            public void componentSelected (ButtonEvent ce)
            {
                hide ();
            }
        });
    }

}
